<template>
    <span>获取验证码({{ count }}s)</span>
</template>

<script setup lang="ts" name="Time">
    import { ref,watch} from 'vue';

    const count = ref<number>(5)

    let {time} = defineProps(['time'])
    let $emit = defineEmits(['getTime'])
    // 监听父组件的变化
    watch(()=>time,()=>{
        // 定时器
        let timer = setInterval(()=>{
            count.value--
            if(count.value<=0){
                clearInterval(timer);
                count.value = 5;
                $emit('getTime',false);
            }
        },1000)
    },{
        immediate:true
        }
    )
</script>

<style>

</style>